classdef IntInv < Cell
    
    properties
    end
    
    methods
        
        function this = IntInv(poles,g)
            this.Name = 'Inverting Integrator';
            this.Poles = poles;
            this.Zeros = [];
            this.Gain = g;
            wp = abs(poles);
            this.calcCell(wp,g);
            this.ImagePath = 'Stages Schematics/Int_Inv.png';

        end
        
        function calcCell(obj,wp,g)
            if wp < 1000
                resists(2) = 5e3;
            else
                resists(2) = 10e3;
            end
            caux = 1/(wp*resists(2));
            resists(1) = resists(2)/g;
            
            obj.Caps = caux;
            obj.Resists = resists;
            %Sensibilidad de Wp
            sens(1) = 0;
            sens(2) = -1;
            sens(3) = -1;
            obj.Senswp = sens;
            %Sensibilidad de G
            sens(1) = -1;
            sens(2) = 1;
            sens(3) = 0;
            obj.SensG = sens;
            obj.error = ~obj.validateComponents(obj.Resists, obj.Caps);
        end
        
        function componentChange(obj,component,value)
            obj.error = 0;
            caps = obj.Caps;
            resists = obj.Resists;
            switch component
                case 1
                    obj.Resists(1) = value;
                    obj.Resists(2) = value*obj.Gain;
                    obj.Caps(1) = 1/(abs(obj.Poles)*value);
                case 2
                    obj.Resists(2) = value;
                    obj.Caps(1) = 1/(abs(obj.Poles)*value);
                    obj.Resists(1) = obj.Resists(2)/obj.Gain;
                case 3
                    obj.Caps(1) = value;
                    obj.Resists(2) = 1/(abs(obj.Poles)*value);
                    obj.Resists(1) = obj.Resists(2)/obj.Gain;
            end
            
            status = obj.validateComponents(obj.Resists,obj.Caps);
            if ~status
                obj.Resists = resists;
                obj.Caps = caps;
                obj.error = 1;
            end
        end
    end
end